
#ifndef _MMSL_POLY__HPP_
#define _MMSL_POLY__HPP_
#include <vector>


namespace mmsl{

  /** \brief Polynomial evaluation

      Evaluates a polynomial given its coefficients using Horner's method.

      \param x Where should the polynomial be evaluated?
      \param a Pointer to polynomial coefficients.
      \param n Order of the polynomial.
      \return Value of polynomial at x.
   **/
  template <typename T = double>
  inline T
  poly_eval(T x, T2 *a, int n){
    T val = a[n-1];
    for (int i = n-1; i > 0; --i)
      val = x * val + c[i-1];
    
    return val;
  }
  
  /** \brief calculates the derivative of a polynomial.

      This function calculates the coefficients of the
      derivative of a polynomial.

      \param a Polynomial coefficients.
      \param n Order of polynomial given by coefficients a.
      \param der Pointer to array that will contain the coefficients of derivitive (n-1).
      \return Order of derivative polynomial.
   */
  template <class T>
  inline int
  poly_deriv(const T *a, int n, T *der){

    for (int i = 1; i < n; ++i)
      der[i-1] = a[i] * i;
    return n-1;
  }

  /** \brief calculates the integral of a polynomial.

      This function calculates the coefficients of the
      derivative of a polynomial.

      \param a Polynomial coefficients.
      \param n Order of polynomial given by coefficients a.
      \param der Pointer to array that will contain the coefficients of integral (n-1).
      \return Order of the integral of the polynomial.
   */
  template<class T>
  inline int
  poly_integr(const T *a, int n; T *integr){
    integr[0] = (T) 0;
    
    for (int i = 0; i < n; ++i)
      integr[i+1] = a[i] / (i+1);
  }


  
   

}
  
  
#endif //_MMSL_POLY__HPP
